﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InheritanceApplication
{
    interface IToolItem
    {
        void UseItem();
    }

    abstract class BaseItem
    {
        public abstract void DisplayName();
    }

    class Diamond : BaseItem
    {
        public override void DisplayName()
        {
            Console.WriteLine("A Diamond");
        }
    }

    class Rope : BaseItem, IToolItem
    {
        public override void DisplayName()
        {
            Console.WriteLine("A Rope");
        }
        public void UseItem()
        {
            Console.WriteLine("Using my rope");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<BaseItem> myBackpack = new List<BaseItem>();

            myBackpack.Add(new Diamond());
            myBackpack.Add(new Rope());

            myBackpack[0].DisplayName();
            myBackpack[1].DisplayName();

            foreach (var allBackpackItems in myBackpack)
                if (allBackpackItems is IToolItem)
                    ((IToolItem)allBackpackItems).UseItem();

            Console.Read();
        }
    }
}
